// pages/index/index.js
var api = require('../../utils/api.js');
var sliderWidth = 96;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    tabs: ["简约", "中式", "欧式", "美式"],
    activeIndex: 0,
    loupanlist: [],//楼盘列表
    anlilist: [],
    after_service: [],
    stylecases: [[], [], [], []]
  },

  loadswiper() {
    api.get({
      url: 'home/slides/1',
      success: data => {
        if (data.code == 1) {
          this.setData({
            movies: data.data[0].items
          })
        }
      }
    });
  },

  /**
   * 生命周期函数--监听页面加载
   */

  onLoad: function (options) {
    this.loadswiper();
    //this.loadloupan();
    //this.loadcases();
   // this.loadfuwu();
    //this.loadafterservice();
    this.dialog = this.selectComponent("#mydialog");
    this.loadcitys()
    api.getparams();
   // this.this.loadonlineformimg();
  },
  tabClick: function (e) {
    this.setData({
      activeIndex: e.currentTarget.id
    });
  },
  loadonlineformimg() {
    api.get({
      url: 'home/slides/9',
      success: data => {
        if (data.code == 1) {
          this.setData({
            formimg: data.data[0].items
          })
        }
      }
    });
  },
  loadfuwu() {
    api.get({
      url: 'home/slides/3',
      success: data => {
        if (data.code == 1) {
          this.setData({
            fuwulist: data.data[0].items
          })
        }
      }
    });
  },
  loadafterservice() {
    api.get({
      url: 'home/slides/4',
      success: data => {
        if (data.code == 1) {
          this.setData({
            after_service: data.data[0].items
          })
        }
      }
    });
  },

  // 城市信息
  loadcitys() {
    api.get({
      url: 'home/attribute/11',
      success: data => {
        if (data.code == 1) {
          this.setData({
            citys:data.data[0].items
          })
        }
      }
    });
  },
  callphonenum() {
    wx.makePhoneCall({
      phoneNumber: '4001529288'
    })
  },

  formSubmit(e) {
    //提交表单数据
    console.log(e)
    api.post({
      url: '/portal/diyform/insert',
      data: e.detail.value,
      success: data => {
        if (data.code == "1") {
          wx.showToast({ title: '报名成功', icon: 'success' })
        }
        if (data.code == "0") {
          wx.showToast({ title: data.msg, icon: 'none' })
        }
      }
    })
  },


  

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  //this.dialog.showModal();
  },

  //加载热装楼盘
  loadloupan() {
    api.get({
      url: '/portal/lists/getCategoryPostLists',
      data: {
        category_id: 1,
        field: 'post.id,post.post_title,post.more',
        is_top: 1,
        order: '-post.id'
      },
      success: data => {
        if (data.code == '1') {
          this.setData({
            loupanlist: data.data.list
          })
        }
      }
    })
  },
  //加载家装案例
  loadcases() {
    api.get({
      url: '/portal/lists/getCategoryPostLists',
      data: {
        category_id: 2,
        field: 'post.id,post.post_title,post.more',
        is_top: 1,
        order: '+list_order'
      },
      success: data => {
        if (data.code == '1') {
          let stylecases = this.data.stylecases;
          let arr = data.data.list;
          for (var i = 0; i < arr.length; i++) {
            stylecases[arr[i].more.style].push(arr[i])
          }

          this.setData({
            stylecases: stylecases
          })
        }
      }
    })
  },

  _hideModal() {
    wx.switchTab({
      url: 'index',
    })
  },

  _submitForm(e){
    //提交表单数据
    console.log(e)
    api.post({
      url:'/portal/diyform/insert',
      data:e.detail.value,
      success:data=>{
        if(data.code=="1"){
          this.dialog.showmask('success','报名成功');
          this.dialog.hideModal();
        }
        if (data.code == "0"){
          this.dialog.showmask('none', data.msg);
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    this.dialog.hideModal();
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})